package com.bjtu.ptsite.controller;


import com.bjtu.ptsite.model.Result;
import com.bjtu.ptsite.tracker.client.TrackerClient;
import com.bjtu.ptsite.tracker.entity.TrackerRequest;
import com.bjtu.ptsite.utils.AliOSSUtils;
import com.bjtu.ptsite.utils.UUIDUtils;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 *
 * @author Zehao Wang, Junjie Zhang, Yutao Wei
 *
 */
@CrossOrigin
@Slf4j
@RestController
@RequestMapping("/test")
public class TestContorller {


    @Autowired
    AliOSSUtils aliOssUtils;
    @Autowired
    TrackerClient trackerClient;
    @ApiOperation("测试oss")
    @PostMapping("/uploadOss")
    public Result uploadOss() throws IOException {
        File file = new File("E:\\torrent\\abc.txt");

        String messageId = UUIDUtils.generateUUID();
        String datePath = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy/MM/dd"));
        String fileName = datePath + "/" + messageId + ".torrent";
        String fileUrl = aliOssUtils.uploadFile(file, fileName);
        System.out.println(fileUrl);
        return Result.success(fileUrl);

    }

    @ApiOperation("getAnn")
    @PostMapping("/getAnn")
    public Result getAnn() throws IOException {

        trackerClient.dumpRegisteredTorrents();

        return Result.success();

    }


}
